/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package controller.Actions;

import controller.Forms.ResponsibleForm;
import dao.ResponsibleDAO;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import model.Erro;
import model.Responsible;
import model.User;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

/**
 *
 * @author Adriano
 */
public class ResponsibleAction extends Action {

    @Override
    public ActionForward execute(ActionMapping mapping,
            ActionForm form,
            HttpServletRequest request,
            HttpServletResponse response) throws Exception {
        try {

            User u = (User) request.getSession().getAttribute("User");
            if (u == null) {
                request.getSession().setAttribute("ErroMSG", Erro.erroMsg[Erro.NAO_AUTENTICADO]);
                return mapping.findForward("erroAlias");
            }    
            ResponsibleForm responsibleForm = (ResponsibleForm) form;
            Responsible responsible = new Responsible();

            responsible.setTxtName(responsibleForm.getTxtName());
            responsible.setTxtCpf(responsibleForm.getTxtCpf().replace(".","").replace(".","").replace("-", ""));
            responsible.setTxtRg(responsibleForm.getTxtRg());
            responsible.setTxtQualification(responsibleForm.getTxtQualification());
            responsible.setLstStatusR(responsibleForm.getLstStatusR());
            
            
            ResponsibleDAO responsibleDAO = new ResponsibleDAO();
            
            responsibleDAO.create(responsible);
            responsibleDAO.closeDAO();
            
            
            return mapping.findForward("homeAlias");
        } catch (Exception e) {
            return null;
        }

    }

}
